<template>
  <div class="view-container">
    <div class="main-content">
      <div class="list-container">
        <div class="my-tabs-container">
          <div class="my-tabs">
            <el-tabs
              v-model="activeName"
              @tab-click="handleClick"
            >
              <el-tab-pane
                label="配送商信用"
                name="distributorCredit"
              />
              <el-tab-pane
                label="代理商信用"
                name="agentCredit"
              />
              <el-tab-pane
                label="商销客户信用"
                name="sellerCredit"
              />
            </el-tabs>
          </div>
        </div>
        <component
          :is="activeName"
          ref="comp"
          navigation="finance"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { defineAsyncComponent, reactive, toRefs } from 'vue'
import { useRoute, useRouter } from 'vue-router'

export default {
  components: {
    distributorCredit: defineAsyncComponent(() =>
      import('./distributorCredit.vue')
    ),
    agentCredit: defineAsyncComponent(() => import('./agentCredit.vue')),
    sellerCredit: defineAsyncComponent(() => import('./sellerCredit.vue')),
  },
  setup(props, context) {
    const route = useRoute()
    const router = useRouter()
    var datas = reactive({
      activeName: route.query.tabs || 'distributorCredit',
      cashRef: null,
      comp: null,
    })
    const handleClick = (tab, event) => {
      console.log(tab, event)
      router.push({
        name: 'creditList',
        query: {
          tabs: tab.props.name,
        },
      })
    }
    const createCashDeposit = () => {
      datas.cashRef.open()
    }
    const createSuccess = () => {
      datas.comp.refreshList()
    }
    return {
      ...toRefs(datas),
      handleClick,
      createCashDeposit,
      createSuccess,
    }
  },
}
</script>

